package Manage;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import Info.BaogaoAI;
import Util.DatabaseConn;


public class BaogaoAM {
	private Connection conn;
	private ResultSet rs;
	private PreparedStatement pstmt;
	public List<BaogaoAI> findAll() {
		List<BaogaoAI> bas = new ArrayList<BaogaoAI>();
		Connection conn = null;
		try {
			 conn = DatabaseConn.getConnection();
		     pstmt = conn.prepareStatement("select * from baogaoa");	     
		     rs = pstmt.executeQuery();
		     while(rs.next()){
				int id =  rs.getInt("id");
				String name = rs.getString("name");
				String age = rs.getString("age");
				String sex = rs.getString("sex");
				String card = rs.getString("card");
				String num = rs.getString("num");
				String type = rs.getString("type");
				String xin = rs.getString("xin");
				String gan = rs.getString("gan");
				String pi = rs.getString("pi");
				String fei = rs.getString("fei");
				String xueya = rs.getString("xueya");
				String xuechanggui = rs.getString("xuechanggui");
				String yijian = rs.getString("yijian");
				String time = rs.getString("time");
		     	BaogaoAI ba = new BaogaoAI(id, name, age, sex, card, num, type, xin, gan, pi, fei, xueya, xuechanggui, yijian, time);
		     	bas.add(ba);
			}
		} catch (Exception e) {

		} finally {
			DatabaseConn.closeConn(conn);
		}
		return bas;
	}
	
	public BaogaoAI Find(String card) {
		new DatabaseConn();
		BaogaoAI ba = null;
		try {
			conn = DatabaseConn.getConnection();
			pstmt = conn.prepareStatement("select * from baogaoa where card=?");
			pstmt.setString(1, card);
			rs = pstmt.executeQuery();
			while (rs.next()) {
				int id =  rs.getInt("id");
				String name = rs.getString("name");
				String age = rs.getString("age");
				String sex = rs.getString("sex");
				String num = rs.getString("num");
				String type = rs.getString("type");
				String xin = rs.getString("xin");
				String gan = rs.getString("gan");
				String pi = rs.getString("pi");
				String fei = rs.getString("fei");
				String xueya = rs.getString("xueya");
				String xuechanggui = rs.getString("xuechanggui");
				String yijian = rs.getString("yijian");
				String time = rs.getString("time");
				ba = new BaogaoAI(id, name, age, sex, card, num, type, xin, gan, pi, fei, xueya, xuechanggui, yijian, time);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			DatabaseConn.closeConn(conn);
		}
		return ba;
	}

}
